package com.dataaccess.dataaccess.web.web;


import cn.hutool.json.JSONObject;
import com.dataaccess.dataaccess.common.base.BaseService;
import com.dataaccess.dataaccess.common.utils.Dict;
import com.dataaccess.dataaccess.common.utils.appkit.FirefightingiotKit;
import com.dataaccess.dataaccess.config.rocketmq.UserProducer;
import com.dataaccess.dataaccess.model.AlarmAllDeviceDataChanged;
import com.dataaccess.dataaccess.support.annotaion.At;
import com.dataaccess.dataaccess.support.model.RespEntity;
import com.dataaccess.dataaccess.support.utils.MyLogger;
import com.dataaccess.dataaccess.support.utils.requestutil.HttpRequestUtil;
import com.dataaccess.dataaccess.web.mapper.AlarmAllDeviceDataChangedMapper;
import com.dataaccess.dataaccess.web.service.UploadService;
import com.dataaccess.dataaccess.web.service.VisualizationVideoAlarmService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;
import java.util.UUID;


/**
 * 消防视频报警信息上传控制
 *
 * @author Yang
 */
@RestController
@RequestMapping("video")
public class VisualizationVideoAlarmController  extends BaseService {

    @Resource
    public MyLogger logger;
    @Resource
    private VisualizationVideoAlarmService videoAlarmService;
    @Resource
    private AlarmAllDeviceDataChangedMapper alarmAllDeviceDataChangedMapper;
    @Resource
    UserProducer userProducer;
    @Resource
    DeviceDataAsyncController deviceDataAsyncController;
    @Resource
    private UploadService uploadService;

    /**
     * 接受报警信息
     *
     * @param request
     * @param map
     * @return
     * @throws Exception
     */
    @At(value = "/videoAlarm", method = RequestMethod.POST)
    public JSONObject videoAlarmInfo(HttpServletRequest request, Map<String, Object> map) throws Exception {
        return videoAlarmService.VisualizationInfo(request, Dict.create(map));
    }

    /**
     * @Author YangYu
     * @Description 浪潮
     * @Date Created in 16:55 2022/4/15
     * @Param [jsonParam]
     */
    @At(value = "/waveBox", method = RequestMethod.POST)
    public RespEntity waveBox(HttpServletRequest request) throws Exception {
        JSONObject jsonParam = HttpRequestUtil.commonHttpRequestParamConvert(getRequest());
        logger.info("waveBox" + "------" + jsonParam);
        //报警数据
        AlarmAllDeviceDataChanged alarmAllDeviceDataChanged = new AlarmAllDeviceDataChanged();
        alarmAllDeviceDataChanged.setId(UUID.randomUUID().toString());
        alarmAllDeviceDataChanged.setJsondata(jsonParam.toString());
        alarmAllDeviceDataChanged.setType("浪潮");
        alarmAllDeviceDataChangedMapper.insert(alarmAllDeviceDataChanged);
        jsonParam.put("deviceFlag", "waveBox");
        String mqFlag = FirefightingiotKit.getStr("mqFlag", "mq");
        if (mqFlag.equals("1")) {
            return videoAlarmService.waveBox(jsonParam);
        } else if (mqFlag.equals("3")) {
            userProducer.produder(jsonParam.toString());
        }
        return RespEntity.success();
    }

    /**
     * 消除报警信息
     *
     * @param request
     * @param map
     * @return
     * @throws Exception
     */
    @At(value = "/videoAlarmStop", method = RequestMethod.POST)
    public JSONObject VisualizationStop(HttpServletRequest request, Map<String, Object> map) throws Exception {
        return videoAlarmService.VisualizationStop(request, Dict.create(map));
    }

    /**
     * 萤石云视频报警信息
     *
     * @param jsonParam
     * @return
     * @throws Exception
     */
    @At(value = "/fluoriteCloud", method = RequestMethod.POST)
    public RespEntity fluoriteCloud(@RequestBody(required = false) JSONObject jsonParam) throws Exception {
        logger.info("fluoriteCloud" + "------" + jsonParam);
        //报警数据
        AlarmAllDeviceDataChanged alarmAllDeviceDataChanged = new AlarmAllDeviceDataChanged();
        alarmAllDeviceDataChanged.setId(UUID.randomUUID().toString());
        alarmAllDeviceDataChanged.setJsondata(jsonParam.toString());
        alarmAllDeviceDataChangedMapper.insert(alarmAllDeviceDataChanged);
        jsonParam.put("deviceFlag", "video");
        String mqFlag = FirefightingiotKit.getStr("mqFlag", "mq");
        if (mqFlag.equals("1")) {
            return videoAlarmService.fluoriteCloud(jsonParam);
        } else if (mqFlag.equals("3")) {
            userProducer.produder(jsonParam.toString());
        }
        return RespEntity.success();
    }
    /**
     * @Author YangYu
     * @Description 大户云睿（电动车识别）
     * @Date Created in 11:02 2022/1/21
     * @Param [jsonParam]
     */

    @At(value = "/daHuaYunRui", method = RequestMethod.POST)
    public RespEntity daHuaYunRui(@RequestBody(required = false) JSONObject jsonParam) throws Exception {
        logger.info("daHuaYunRui" + "------" + jsonParam);
        //报警数据
        AlarmAllDeviceDataChanged alarmAllDeviceDataChanged = new AlarmAllDeviceDataChanged();
        alarmAllDeviceDataChanged.setId(UUID.randomUUID().toString());
        alarmAllDeviceDataChanged.setJsondata(jsonParam.toString());
        alarmAllDeviceDataChanged.setType("daHuaYunRui");
        alarmAllDeviceDataChangedMapper.insert(alarmAllDeviceDataChanged);
        jsonParam.put("deviceFlag", "daHuaYunRui");
        String mqFlag = FirefightingiotKit.getStr("mqFlag", "mq");
        if (mqFlag.equals("1")) {
            return videoAlarmService.daHuaYunRui(jsonParam);
        }else if(mqFlag.equals("3")){
            userProducer.produder(jsonParam.toString());
        }
        return RespEntity.success();

    }
    /**
     * 阿里云摄像头
     *
     * @param jsonParam
     * @return
     * @throws Exception
     */
    @At(value = "/aliyunCamera", method = RequestMethod.POST)
    public JSONObject aliyunCamera(@RequestBody(required = false) JSONObject jsonParam) throws Exception {
        //异步处理
        deviceDataAsyncController.aliyunAsyncCamera(jsonParam);
        JSONObject ret = new JSONObject();
        ret.put("errcode", 0);
        ret.put("errmsg", "ok");
        return ret;
    }


    /**
     * @Author YangYu
     * @Description 博观盒子（宇视）
     * @Date Created in 9:55 2021/11/17
     * @Param [jsonParam]
     */

    @At(value = "/unloadingOilOrSafe", method = RequestMethod.POST)
    public RespEntity unloadingOilCamera(@RequestBody(required = false) JSONObject jsonParam) throws Exception {
        logger.info("unloadingOilOrSafe" + "------" + jsonParam);
        //报警数据
        AlarmAllDeviceDataChanged alarmAllDeviceDataChanged = new AlarmAllDeviceDataChanged();
        alarmAllDeviceDataChanged.setId(UUID.randomUUID().toString());
        alarmAllDeviceDataChanged.setJsondata(jsonParam.toString());
        alarmAllDeviceDataChanged.setType("unloadingOilOrSafe");
        alarmAllDeviceDataChangedMapper.insert(alarmAllDeviceDataChanged);
        jsonParam.put("deviceFlag", "unloadingOilOrSafe");
        String mqFlag = FirefightingiotKit.getStr("mqFlag", "mq");
        if (mqFlag.equals("1")) {
            return videoAlarmService.unloadingOilOrSafe(jsonParam);
        } else if (mqFlag.equals("3")) {
            userProducer.produder(jsonParam.toString());
        }
        return RespEntity.success();

    }
    /**
     * @Author YangYu
     * @Description 海康超脑
     * @Date Created in 9:55 2021/11/17
     * @Param [jsonParam]
     */

    @At(value = "/hkHyperbrain", method = RequestMethod.POST)
    public RespEntity hkHyperbrain(@RequestBody(required = false) JSONObject jsonParam) throws Exception {
        logger.info("hkHyperbrain" + "------" + jsonParam);
        //报警数据
        AlarmAllDeviceDataChanged alarmAllDeviceDataChanged = new AlarmAllDeviceDataChanged();
        alarmAllDeviceDataChanged.setId(UUID.randomUUID().toString());
        alarmAllDeviceDataChanged.setJsondata(jsonParam.toString());
        alarmAllDeviceDataChanged.setType("hkHyperbrain");
        alarmAllDeviceDataChangedMapper.insert(alarmAllDeviceDataChanged);
        jsonParam.put("deviceFlag", "hkHyperbrain");
        String mqFlag = FirefightingiotKit.getStr("mqFlag", "mq");
        if (mqFlag.equals("1")) {
            return videoAlarmService.hkHyperbrain(jsonParam);
        } else if (mqFlag.equals("3")) {
            userProducer.produder(jsonParam.toString());
        }
        return RespEntity.success();

    }

    /**
     * 海康梯控报警信息
     *
     * @param jsonParam
     * @return
     * @throws Exception
     */
    @At(value = "/hikvision", method = RequestMethod.POST)
    public RespEntity hikvision(@RequestBody(required = false) JSONObject jsonParam) throws Exception {
        logger.info("hikvision" + "------" + jsonParam);
        //报警数据
        AlarmAllDeviceDataChanged alarmAllDeviceDataChanged = new AlarmAllDeviceDataChanged();
        alarmAllDeviceDataChanged.setId(UUID.randomUUID().toString());
        alarmAllDeviceDataChanged.setJsondata(jsonParam.toString());
        alarmAllDeviceDataChanged.setType("hikvision");
        alarmAllDeviceDataChangedMapper.insert(alarmAllDeviceDataChanged);
        jsonParam.put("deviceFlag", "hikvision");
        String mqFlag = FirefightingiotKit.getStr("mqFlag", "mq");
        if (mqFlag.equals("1")) {
            return videoAlarmService.hikvision(jsonParam);
        } else if (mqFlag.equals("3")) {
            userProducer.produder(jsonParam.toString());
        }
        return RespEntity.success();
    }


    /**
     * 海康事件订阅
     *
     * @param jsonParam
     * @return
     * @throws Exception
     */
    @At(value = "/eventSubscriptionsHK", method = RequestMethod.POST)
    public RespEntity eventSubscriptionsHK(@RequestBody(required = false) JSONObject jsonParam) throws Exception {
        RespEntity respEntity = videoAlarmService.eventSubscriptionsHK(jsonParam);
        return RespEntity.success();
    }

    /**
     * 海康事件订阅回调
     *
     * @param jsonParam
     * @return
     * @throws Exception
     */
    @At(value = "/eventSubscriptionsHKRest", method = RequestMethod.POST)
    public RespEntity eventSubscriptionsHKRest(@RequestBody(required = false) JSONObject jsonParam) throws Exception {
        logger.info("hikvisionBounds" + "------" + jsonParam);
        //报警数据
        AlarmAllDeviceDataChanged alarmAllDeviceDataChanged = new AlarmAllDeviceDataChanged();
        alarmAllDeviceDataChanged.setId(UUID.randomUUID().toString());
        alarmAllDeviceDataChanged.setJsondata(jsonParam.toString());
        alarmAllDeviceDataChanged.setType("hikvisionBounds");
        alarmAllDeviceDataChangedMapper.insert(alarmAllDeviceDataChanged);
        jsonParam.put("deviceFlag", "hikvisionBounds");
        String mqFlag = FirefightingiotKit.getStr("mqFlag", "mq");
        if (mqFlag.equals("1")) {
            return videoAlarmService.eventSubscriptionsHKRest(jsonParam);
        } else if (mqFlag.equals("3")) {
            userProducer.produder(jsonParam.toString());
        }
        return RespEntity.success();
    }

    /**
     * @Author YangYu
     * @Description 海康(加油站)
     * @Date Created in 14:23 2024/8/6
     * @Param [jsonParam]
     */

    @At(value = "/hikGasStation", method = RequestMethod.POST)
    public RespEntity hikGasStation(@RequestBody(required = false) JSONObject jsonParam) throws Exception {
        logger.info("hikGasStation" + "------" + jsonParam);
        //报警数据
        AlarmAllDeviceDataChanged alarmAllDeviceDataChanged = new AlarmAllDeviceDataChanged();
        alarmAllDeviceDataChanged.setId(UUID.randomUUID().toString());
        alarmAllDeviceDataChanged.setJsondata(jsonParam.toString());
        alarmAllDeviceDataChanged.setType("hikGasStation");
        alarmAllDeviceDataChangedMapper.insert(alarmAllDeviceDataChanged);
        return videoAlarmService.hikGasStation(jsonParam);
    }

    /**
     * @Author YangYu
     * @Description 浪潮
     * @Date Created in 16:55 2022/4/15
     * @Param [jsonParam]
     */
    @At(value = "/yunCongGasStationAnalyzer", method = RequestMethod.POST)
    public RespEntity yunCongGasStationAnalyzer(HttpServletRequest request) throws Exception {
        JSONObject jsonParam = HttpRequestUtil.commonHttpRequestParamConvert(getRequest());
        logger.info("yunCongGasStationAnalyzer" + "------" + jsonParam);
        //报警数据
        AlarmAllDeviceDataChanged alarmAllDeviceDataChanged = new AlarmAllDeviceDataChanged();
        alarmAllDeviceDataChanged.setId(UUID.randomUUID().toString());
        alarmAllDeviceDataChanged.setJsondata(jsonParam.toString());
        alarmAllDeviceDataChanged.setType("云从");
        alarmAllDeviceDataChangedMapper.insert(alarmAllDeviceDataChanged);
        jsonParam.put("deviceFlag", "yunCongGasStationAnalyzer");
        String mqFlag = FirefightingiotKit.getStr("mqFlag", "mq");
        if (mqFlag.equals("1")) {
            return videoAlarmService.yunCongGasStationAnalyzer(jsonParam);
        } else if (mqFlag.equals("3")) {
            userProducer.produder(jsonParam.toString());
        }
        return RespEntity.success();
    }
    /**
     * @Author YangYu
     * @Description 融合永道视频分析
     * @Date Created in 16:55 2022/4/15
     * @Param [jsonParam]
     */
    @At(value = "/rongHeYongDao", method = RequestMethod.POST)
    public RespEntity rongHeYongDao(@RequestBody(required = false) JSONObject jsonParam) throws Exception {
        jsonParam = HttpRequestUtil.commonHttpRequestParamConvert(getRequest());
        logger.info("rongHeYongDao" + "------" + jsonParam);
        //报警数据
        AlarmAllDeviceDataChanged alarmAllDeviceDataChanged = new AlarmAllDeviceDataChanged();
        alarmAllDeviceDataChanged.setId(UUID.randomUUID().toString());
        alarmAllDeviceDataChanged.setJsondata(jsonParam.toString());
        alarmAllDeviceDataChanged.setType("融合永道");
        alarmAllDeviceDataChangedMapper.insert(alarmAllDeviceDataChanged);
        jsonParam.put("deviceFlag", "rongHeYongDao");
        String mqFlag = FirefightingiotKit.getStr("mqFlag", "mq");
        if (mqFlag.equals("1")) {
            return videoAlarmService.rongHeYongDao(jsonParam);
        } else if (mqFlag.equals("3")) {
            userProducer.produder(jsonParam.toString());
        }
        return RespEntity.success();
    }
    /**
     * @Author YangYu
     * @Description 融合永道视频分析
     * @Date Created in 16:55 2022/4/15
     * @Param [jsonParam]
     */
    @At(value = "/rongHeYongDao_Request", method = RequestMethod.POST)
    public RespEntity rongHeYongDao() throws Exception {
        JSONObject jsonParam = HttpRequestUtil.commonHttpRequestParamConvert(getRequest());
        logger.info("rongHeYongDao" + "------" + jsonParam);
        //报警数据
        AlarmAllDeviceDataChanged alarmAllDeviceDataChanged = new AlarmAllDeviceDataChanged();
        alarmAllDeviceDataChanged.setId(UUID.randomUUID().toString());
        alarmAllDeviceDataChanged.setJsondata(jsonParam.toString());
        alarmAllDeviceDataChanged.setType("融合永道");
        alarmAllDeviceDataChangedMapper.insert(alarmAllDeviceDataChanged);
        jsonParam.put("deviceFlag", "rongHeYongDao");
        String mqFlag = FirefightingiotKit.getStr("mqFlag", "mq");
        if (mqFlag.equals("1")) {
            return videoAlarmService.rongHeYongDao(jsonParam);
        } else if (mqFlag.equals("3")) {
            userProducer.produder(jsonParam.toString());
        }
        return RespEntity.success();
    }

    /**
     * @Author YangYu
     * @Description 火焰识别（京电云）
     * @Date Created in 16:55 2022/4/15
     * @Param [jsonParam]
     */
    @At(value = "/flameJDY", method = RequestMethod.POST)
    public RespEntity flameJDY(@RequestBody(required = false) JSONObject jsonParam) throws Exception {
        logger.info("flameJDY" + "------" + jsonParam);
        //报警数据
        AlarmAllDeviceDataChanged alarmAllDeviceDataChanged = new AlarmAllDeviceDataChanged();
        alarmAllDeviceDataChanged.setId(UUID.randomUUID().toString());
        alarmAllDeviceDataChanged.setJsondata(jsonParam.toString());
        alarmAllDeviceDataChanged.setType("flameJDY");
        alarmAllDeviceDataChangedMapper.insert(alarmAllDeviceDataChanged);
        jsonParam.put("deviceFlag", "flameJDY");
        String mqFlag = FirefightingiotKit.getStr("mqFlag", "mq");
        if (mqFlag.equals("1")) {
            return videoAlarmService.flameJDY(jsonParam);
        } else if (mqFlag.equals("3")) {
            userProducer.produder(jsonParam.toString());
        }
        return RespEntity.success();
    }
}
